Hi, |
Re: Sorting question
Hi, string szDate = "October 16, 2012" Date d = szDate string s = stringOf(d, "yyyy/M/dd") print s
Skip s = createString()
for each row of your array do {
Date d = aDate[i]
put(s, stringOf(d, aDate[i]), aDate[i])
}
|
Re: Sorting question adevicq - Wed Oct 31 10:17:56 EDT 2012
Hi, string szDate = "October 16, 2012" Date d = szDate string s = stringOf(d, "yyyy/M/dd") print s
Skip s = createString()
for each row of your array do {
Date d = aDate[i]
put(s, stringOf(d, aDate[i]), aDate[i])
}
Hi again,
string aDates[] = {
"October 25, 2012",
"October 16, 2012",
"October 15, 2012",
"October 23, 2012"
}
Skip s = createString
string sz
for (i = 0; i < sizeof(aDates); ++i) {
Date d = aDates[i]
sz = stringOf(d, "yyyy/M/dd")
put(s, sz, aDates[i])
}
for sz in s do print sz "\n"
delete s
|
Re: Sorting question This script will be run on many modules with different dates. Is there a better method to choose the seed date? Thank you. |
Re: Sorting question adevicq - Wed Oct 31 10:22:26 EDT 2012
Hi again,
string aDates[] = {
"October 25, 2012",
"October 16, 2012",
"October 15, 2012",
"October 23, 2012"
}
Skip s = createString
string sz
for (i = 0; i < sizeof(aDates); ++i) {
Date d = aDates[i]
sz = stringOf(d, "yyyy/M/dd")
put(s, sz, aDates[i])
}
for sz in s do print sz "\n"
delete s
This is a better approach then the one I was about to suggest. However some tweaks:
string aDates[] = {
"Tuesday, October 16, 2012",
"Monday, October 15, 2012",
"Thursday, October 25, 2012",
"Tuesday, October 23, 2012",
"Monday, October 29, 2012",
"Friday, October 19, 2012",
"Monday, October 22, 2012",
"Wednesday, October 24, 2012",
"Wednesday, October 17, 2012",
"Thursday, October 18, 2012",
"Friday, October 26, 2012"
}
Skip s = create() // KEY: 'int' date in seconds; DATA: 'string' date
string sz
for (i = 0; i < sizeof(aDates); i++) {
put(s, intOf(dateOf(aDates[i])), aDates[i])
}
i = 0
for sz in s do
{ aDates[i++] = sz
}
for (i = 0; i < sizeof(aDates); i++) {print aDates[i] "\n"}
delete s
|
Re: Sorting question llandale - Wed Oct 31 12:24:16 EDT 2012 This is a better approach then the one I was about to suggest. However some tweaks:
string aDates[] = {
"Tuesday, October 16, 2012",
"Monday, October 15, 2012",
"Thursday, October 25, 2012",
"Tuesday, October 23, 2012",
"Monday, October 29, 2012",
"Friday, October 19, 2012",
"Monday, October 22, 2012",
"Wednesday, October 24, 2012",
"Wednesday, October 17, 2012",
"Thursday, October 18, 2012",
"Friday, October 26, 2012"
}
Skip s = create() // KEY: 'int' date in seconds; DATA: 'string' date
string sz
for (i = 0; i < sizeof(aDates); i++) {
put(s, intOf(dateOf(aDates[i])), aDates[i])
}
i = 0
for sz in s do
{ aDates[i++] = sz
}
for (i = 0; i < sizeof(aDates); i++) {print aDates[i] "\n"}
delete s
|
Re: Sorting question llandale - Wed Oct 31 12:29:35 EDT 2012
Hi Louie, Tuesday, October 16, 2012 Monday, October 15, 2012 Thursday, October 25, 2012 Tuesday, October 23, 2012 Monday, October 29, 2012 Friday, October 19, 2012 Monday, October 22, 2012 Wednesday, October 24, 2012 Wednesday, October 17, 2012 Thursday, October 18, 2012 Friday, October 26, 2012
|
Re: Sorting question adevicq - Wed Oct 31 12:39:56 EDT 2012
Hi Louie, Tuesday, October 16, 2012 Monday, October 15, 2012 Thursday, October 25, 2012 Tuesday, October 23, 2012 Monday, October 29, 2012 Friday, October 19, 2012 Monday, October 22, 2012 Wednesday, October 24, 2012 Wednesday, October 17, 2012 Thursday, October 18, 2012 Friday, October 26, 2012
Of course Skips are sorted ... If you would have inserted a print statement in the loop to fill the skip list, then you would have seen, that the intOf (...) always returns -1, therefore only putting one object to the skip, therefore overwriting the first object in the array with itself - so seemingly doing nothing.
// Search an english locale to read the english dates ...
Locale l
for l in supportedLocales do {
if (region l == "United Kingdom") break
}
if (region l != "United Kingdom") error "Locale not found!"
// ...
string sz
int i
for (i = 0; i < sizeof(aDates); i++) {
// explicitly specify the locale AND the date format here, otherwise your script will not work always
put(s, intOf(date(aDates[i], l, "dddd, MMMM dd, yyyy") ), aDates[i])
}
i = 0
for sz in s do
{ aDates[i++] = sz
}
for (i = 0; i < sizeof(aDates); i++) {print aDates[i] "\n"}
delete s
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|
Re: Sorting question adevicq - Wed Oct 31 12:39:56 EDT 2012
Hi Louie, Tuesday, October 16, 2012 Monday, October 15, 2012 Thursday, October 25, 2012 Tuesday, October 23, 2012 Monday, October 29, 2012 Friday, October 19, 2012 Monday, October 22, 2012 Wednesday, October 24, 2012 Wednesday, October 17, 2012 Thursday, October 18, 2012 Friday, October 26, 2012
I get good results running the code; v9.3.0.6. You did add "int i" yes and fix dateOf to date? I wonder if there is a "Locale" problem? Monday, October 15, 2012 Tuesday, October 16, 2012 Wednesday, October 17, 2012 Thursday, October 18, 2012 Friday, October 19, 2012 Monday, October 22, 2012 Tuesday, October 23, 2012 Wednesday, October 24, 2012 Thursday, October 25, 2012 Friday, October 26, 2012 Monday, October 29, 2012
string aDates[] = {
"Tuesday, October 16, 2012",
"Monday, October 15, 2012",
"Thursday, October 25, 2012",
"Tuesday, October 23, 2012",
"Monday, October 29, 2012",
"Friday, October 19, 2012",
"Monday, October 22, 2012",
"Wednesday, October 24, 2012",
"Wednesday, October 17, 2012",
"Thursday, October 18, 2012",
"Friday, October 26, 2012"
}
Skip s = create() // KEY: 'int' date in seconds; DATA: 'string' date
string sz
int i
for (i = 0; i < sizeof(aDates); i++)
{ put(s, intOf(date(aDates[i])), aDates[i])
}
i = 0
for sz in s do
{ aDates[i++] = sz
}
for (i = 0; i < sizeof(aDates); i++) {print aDates[i] "\n"}
delete s
|
Re: Sorting question |
Re: Sorting question Mathias Mamsch - Wed Oct 31 16:16:47 EDT 2012
Of course Skips are sorted ... If you would have inserted a print statement in the loop to fill the skip list, then you would have seen, that the intOf (...) always returns -1, therefore only putting one object to the skip, therefore overwriting the first object in the array with itself - so seemingly doing nothing.
// Search an english locale to read the english dates ...
Locale l
for l in supportedLocales do {
if (region l == "United Kingdom") break
}
if (region l != "United Kingdom") error "Locale not found!"
// ...
string sz
int i
for (i = 0; i < sizeof(aDates); i++) {
// explicitly specify the locale AND the date format here, otherwise your script will not work always
put(s, intOf(date(aDates[i], l, "dddd, MMMM dd, yyyy") ), aDates[i])
}
i = 0
for sz in s do
{ aDates[i++] = sz
}
for (i = 0; i < sizeof(aDates); i++) {print aDates[i] "\n"}
delete s
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
Thanks for the comments... You're right: I did not check whether the return value was OK or not. Alain |